#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main()
{
    int K;
    cin >> K;
    double v[1001] = { 0 };
    int sum = 0;
    while (K--)
    {
        int N;
        double a;
        cin >> N >> a;
        v[N] += a;
    }
    cin >> K;
    while (K--)
    {
        int N;
        double a;
        cin >> N >> a;
        v[N] += a;
    }
    for (int i = 0; i < 1001; ++i)
    {
        if (v[i] != 0) ++sum;
    }
    cout << sum;
    for (int i = 1000; i >= 0; --i)
    {
        if (v[i] != 0) printf(" %d %.1f", i, v[i]);
    }
    return 0;
}

class Solution {
public:
    vector<int> productExceptSelf(vector<int>& nums) {
        int n = nums.size();
        vector<int> fdp(n);
        vector<int> gdp(n);
        vector<int> ret(n);
        fdp[0] = gdp[n - 1] = 1;
        for (int i = 1; i < n; ++i)
        {
            fdp[i] = fdp[i - 1] * nums[i - 1];
        }
        for (int i = n - 2; i >= 0; --i)
        {
            gdp[i] = gdp[i + 1] * nums[i + 1];
        }
        for (int i = 0; i < n; ++i)
        {
            ret[i] = fdp[i] * gdp[i];
        }
        return ret;
    }

    int countWays(vector<int>& nums) {
        int n = nums.size();
        int res = 0;
        sort(nums.begin(), nums.end());
        for (int k = 0; k <= n; ++k)
        {
            if (k > 0 && nums[k - 1] >= k) continue;
            if (k < n && nums[k] <= k) continue;
            ++res;
        }
        return res;
    }
};